<!--
  Copyright © 2016 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<div class="row">
  <div class="tracker-top-search"
       ng-if="!$state.params.iframe">
    <div class="tracker-search-bar">
      <div class="form-group has-feedback">
        <h2>Tags</h2>
        <button class="btn btn-default add-tags"
          ng-click="TagsController.showAddModal(key)">Add Preferred Tags</button>
      </div>
    </div>
    <div ng-if="!$state.params.iframe">
      <cask-resource-center-button></cask-resource-center-button>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-sm-6 preferred-tags">
    <div ng-if="TagsController.tags.preferredTags.length > 0"
        class="table-responsive">
      <table class="table table-striped" cask-sortable>
        <thead>
          <tr ng-class="{'sort-enabled': TagsController.tags.preferredTags.length > 0}">
            <th data-predicate="name">Preferred Tags</th>
            <th data-predicate="count">Tagged Entities</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="tag in TagsController.tags.preferredTags | orderBy:sortable.predicate:sortable.reverse | myPaginate:TagsController.currentPreferredPage">
            <td>
              <a class="tag preferred user"
                ui-sref="tracker.detail.result({searchQuery: tag.name})">{{ tag.name }}</a>
            </td>
            <td>
              <span class="tagged-entities">{{ tag.count }}</span>
            </td>
            <td ng-if="tag.count > 0">
              <span class="action-link"
                    ng-click="TagsController.demotePreferredTag(tag.name)">Demote</span>
            </td>
            <td ng-if="tag.count === 0">
              <span class="fa fa-trash"
                    ng-click="TagsController.showDeleteModal(tag.name)"></span>
            </td>
          </tr>
          <tr ng-if="TagsController.currentPreferredPage === TagsController.tags.emptyPreferredTags.numPages"
              ng-repeat="empty in TagsController.tags.emptyPreferredTags.emptyArr track by $index"
              class="empty-row">
            <td></td>
            <td></td>
            <td></td>
          </tr>
        </tbody>
      </table>
      <div class="text-left"
          ng-if="TagsController.tags.preferredTags.length > 10">
        <uib-pagination total-items="TagsController.tags.preferredTags.length"
                        max-size="10"
                        force-ellipses="true"
                        ng-model="TagsController.currentPreferredPage"></uib-pagination>
      </div>
    </div>
    <div ng-if="TagsController.tags.preferredTags.length === 0"
        class="well text-center">
      <div class="loading-search" ng-if="TagsController.loadingTags">
        <div class="container-fluid">
          <h3>
            <span class="fa fa-spinner fa-spin"></span>
          </h3>
        </div>
      </div>
      <p ng-if="!TagsController.loadingTags">No preferred tags to display.</p>
    </div>
  </div>
  <div class="col-sm-6 user-tags">
    <div ng-if="TagsController.tags.userTags.length > 0"
        class="table-responsive">
      <table class="table table-striped" cask-sortable>
        <thead>
          <tr ng-class="{'sort-enabled': TagsController.tags.userTags.length > 0}">
            <th data-predicate="name">Business Tags</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="tag in TagsController.tags.userTags | orderBy:sortable.predicate:sortable.reverse | myPaginate:TagsController.currentUserPage">
            <td>
              <a class="tag user"
                ui-sref="tracker.detail.result({searchQuery: tag.name})">{{ tag.name }}</a>
            </td>
            <td>
              <span class="action-link"
                    ng-click="TagsController.promoteUserTag(tag.name)">Promote</span>
            </td>
          </tr>
          <tr ng-if="TagsController.currentUserPage === TagsController.tags.emptyUserTags.numPages"
              ng-repeat="empty in TagsController.tags.emptyUserTags.emptyArr track by $index"
              class="empty-row">
            <td></td>
            <td></td>
          </tr>
        </tbody>
      </table>
      <div class="text-left"
          ng-if="TagsController.tags.userTags.length > 10">
        <uib-pagination total-items="TagsController.tags.userTags.length"
                        max-size="10"
                        force-ellipses="true"
                        ng-model="TagsController.currentUserPage"></uib-pagination>
      </div>
    </div>
    <div ng-if="TagsController.tags.userTags.length === 0"
        class="well text-center">
      <div class="loading-search" ng-if="TagsController.loadingTags">
        <div class="container-fluid">
          <h3>
            <span class="fa fa-spinner fa-spin"></span>
          </h3>
        </div>
      </div>
      <p ng-if="!TagsController.loadingTags">No business tags to display.</p>
    </div>
  </div>
</div>
